Reinstate the reboot-feature code that was accidentally lost as part of the
authorEwan Mellor <ewan@xensource.com>
Thu, 30 Nov 2006 17:28:51 +0000 (17:28 +0000)
committerEwan Mellor <ewan@xensource.com>
Thu, 30 Nov 2006 17:28:51 +0000 (17:28 +0000)
merge in changeset 12189.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/image.py

index 98397d76ca06ecc5936a608dd247e4e7b4dbf287..afff1b084ef5ef17ce85297576287fede168c6e2 100644 (file)
@@ -280,6 +280,7 @@ class HVMImageHandler(ImageHandler):
         log.debug("apic           = %d", self.apic)
 
         self.register_shutdown_watch()
+        self.register_reboot_feature_watch()
 
         return xc.hvm_build(domid          = self.vm.getDomid(),
                             image          = self.kernel,
@@ -420,6 +421,7 @@ class HVMImageHandler(ImageHandler):
 
     def destroy(self):
         self.unregister_shutdown_watch()
+        self.unregister_reboot_feature_watch();
         if not self.pid:
             return
         try:
@@ -470,6 +472,39 @@ class HVMImageHandler(ImageHandler):
 
         return 1 # Keep watching
 
+    def register_reboot_feature_watch(self):
+        """ add xen store watch on control/feature-reboot """
+        self.rebootFeatureWatch = xswatch(self.vm.dompath + "/control/feature-reboot", \
+                                         self.hvm_reboot_feature)
+        log.debug("hvm reboot feature watch registered")
+
+    def unregister_reboot_feature_watch(self):
+        """Remove the watch on the control/feature-reboot, if any. Nothrow
+        guarantee."""
+
+        try:
+            if self.rebootFeatureWatch:
+                self.rebootFeatureWatch.unwatch()
+        except:
+            log.exception("Unwatching hvm reboot feature watch failed.")
+        self.rebootFeatureWatch = None
+        log.debug("hvm reboot feature watch unregistered")
+
+    def hvm_reboot_feature(self, _):
+        """ watch call back on node control/feature-reboot,
+            if node changed, this function will be called
+        """
+        xd = xen.xend.XendDomain.instance()
+        vm = xd.domain_lookup( self.vm.getDomid() )
+
+        status = vm.readDom('control/feature-reboot')
+        log.debug("hvm_reboot_feature fired, module status=%s", status)
+        if status == '1':
+            self.unregister_shutdown_watch()
+
+        return 1 # Keep watching
+
+
 class IA64_HVM_ImageHandler(HVMImageHandler):
 
     ostype = "hvm"